import {reqBanner} from '../../request/api'
//初始状态 
const initState={
banner:[]
}

// actionType
const TYPES={
MINE_CHANGE_BANNER:'MINE_CHANGE_BANNER'
}

// reducer
const reducer=(state=initState,action)=>{
    switch (action.type){
        case TYPES.MINE_CHANGE_BANNER:
            return {
                ...state,
                banner:action.banner
            }
        default:
            return state;
    }
}

// actionCreators
export const actions={
    // 修改轮播图
changeBanner:(banner)=>({type:TYPES.MINE_CHANGE_BANNER,banner}),
// 请求轮播图
requestBanner:()=>(dispatch,getState)=>{
    reqBanner().then(res=>{
        if(res.data.code===200){
            dispatch(actions.changeBanner(res.data.list))
        }
    })
}
}
// selectors
export const getBanner=state=>state.mine.banner;

export default reducer